package com.examples.combobox;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ComboBasic {
	public static void main(String[] args) {
		
		Display d = Display.getDefault();
		Shell s = new Shell(d);
		s.setLayout(new RowLayout());
		
		String[] a = {"a","b","c"};
		
		final Combo c = new Combo(s, SWT.DROP_DOWN);		
		c.setItems(a);
		
		final Combo c1 = new Combo(s, SWT.DROP_DOWN | SWT.READ_ONLY);	
		/* Use of read only is that you cannot choose a default value of you own. You can only choose a value from the dropdown.
		 * 
		 * But in case of normal drop down, you can enter your own value too
		 * */
		c1.setItems(a);
		
		final Combo c2 = new Combo(s, SWT.SIMPLE);
		c2.setItems(a);
		
		Button b = new Button(s, SWT.PUSH);
		b.setText("Button");
		
		b.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println(c.getText());
				System.out.println(c1.getText());
				System.out.println(c2.getText());				
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				
			}
		});
		
		s.open();
		
		while(!s.isDisposed()){
			if(!d.readAndDispatch()) d.sleep();
		}
		//display.dispose(); //Commented only for SWTShowcase application.
	}

}
